<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<script type="text/javascript">
    var status = new Array();
    <logic:iterate id="entry" name="myDataRequestForm" property="dataReqMap">
        <logic:iterate id="owner" name="entry" property="value" indexId="index">
            <logic:lessEqual name="index" value="0">
                status[<bean:write name="owner" property="requestID" />] = new Array();
            </logic:lessEqual>
                status[<bean:write name="owner" property="requestID" />][<bean:write name="index" />] = new Array();
                status[<bean:write name="owner" property="requestID" />][<bean:write name="index" />][0] = '<bean:write name="owner" property="name" />';
                status[<bean:write name="owner" property="requestID" />][<bean:write name="index" />][1] = '<bean:write name="owner" property="status" />';
                status[<bean:write name="owner" property="requestID" />][<bean:write name="index" />][2] = '<bean:write name="owner" property="comments" />';
        </logic:iterate>
    </logic:iterate>

        function makeContent(reqId)
        {
            table = '<table><tr><th>Data Owner<\/th><th>Status<\/th><th>Comments<\/th><\/tr>';
            array = status[reqId];
            for (i = 0; i < array.length; i++)
            {
                table += '<tr><td>' + array[i][0] + '<\/td>';
                table += '<td>' + array[i][1] + '<\/td>';
                table += '<td>' + array[i][2] + '<\/td><\/tr>';
            }
            table += '<\/table>';

            return table;
        }

        $(document).ready(function() {
            // Add tooltips displaying status
            $("#dataTable a").each(function() {
                content = makeContent($(this).attr("id").substring(7)); // Removing 'request' from ID
                $(this).simpletip({
                    content: content
                });
            });

            // Change cancel buttons
            $("#dataTable :submit").button({
                icons: {primary: 'ui-icon-trash'},
                text: false
            });

            // 'DataTablize' the table
            $("#dataTable").dataTable({
                "bPaginate": true,
                "sPaginationType": "full_numbers",
                "bFilter": true,
                "bJQueryUI": true,
                "bAutoWidth": false,
                "aoColumns": [{"sType": "date"}, null, null, null, null, null, null,
                    {"bSearchable": false, "bSortable": false}]
            });
        });
</script>
<div id="myRequests" class="content list">
    <h2>My Data Requests</h2>
    <html:form action="deleteExport">
        <table id="dataTable" cellpadding="0" cellspacing="0" border="0" class="display">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Cohorts</th>
                    <th>SNPs</th>
                    <th>Variables</th>
                    <th>Approved</th>
                    <th>Sent</th>
                    <th>Sent Date</th>
                    <th>Cancel</th>
                </tr>
            </thead>
            <tbody>
                <logic:iterate id="dataRequest" name="myDataRequestForm" property="dataReqMap" type="java.util.Map.Entry">
                    <tr>
                        <td><bean:write name="dataRequest" property="key.requestDate" format="dd MMM yyyy"/></td>
                        <td><bean:write name="dataRequest" property="key.cohorts"/></td>
                        <td><bean:write name="dataRequest" property="key.snps"/></td>
                        <td><bean:write name="dataRequest" property="key.variables"/></td>
                        <td>
                            <a id="request<bean:write name="dataRequest" property="key.requestId"/>">
                                <bean:write name="dataRequest" property="key.approved"/>
                            </a>
                        </td>
                        <td><bean:write name="dataRequest" property="key.sentText"/></td>
                        <td><bean:write name="dataRequest" property="key.sentDate"/></td>
                        <td>
                            <button type="submit" name="requestId" value="<bean:write name="dataRequest" property="key.requestId"/>">Cancel</button>
                        </td>
                    </tr>
                </logic:iterate>
            </tbody>
        </table>
    </html:form>
</div>